﻿using MVVMDemo.Models;
using System.Collections.ObjectModel;
using System.ComponentModel;


namespace MVVMDemo.ViewModels
{
    class MainWindowViewModel : INotifyPropertyChanged
    {
        public MainWindowViewModel()
        {
            UserCollection = new ObservableCollection<UserModel>
            {
                new UserModel
                {
                    Firstname = "User",
                    Lastname = "One"
                },
                new UserModel
                {
                    Firstname = "User",
                    Lastname = "Two"
                },
                new UserModel
                {
                    Firstname = "User",
                    Lastname = "Three"
                },
                new UserModel
                {
                    Firstname = "User",
                    Lastname = "Four"
                },
            };

            m_newUserDetails = new UserModel();
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        public void RaisePropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private UserModel m_selectedUser;

        public UserModel SelectedUser
        {
            get
            {
                return m_selectedUser;
            }

            set
            {
                m_selectedUser = value;
                RaisePropertyChanged(nameof(SelectedUser));
            }
        }

        private ObservableCollection<UserModel> m_userCollection;

        public ObservableCollection<UserModel> UserCollection
        {
            get
            {
                return m_userCollection;
            }

            set
            {
                m_userCollection = value;
                RaisePropertyChanged(nameof(UserCollection));
            }
        }

        private UserModel m_newUserDetails;

        public UserModel NewUserDetails
        {
            get
            {
                return m_newUserDetails;
            }

            set
            {
                m_newUserDetails = value;
                RaisePropertyChanged(nameof(NewUserDetails));
            }
        }
    }
}
